package com.mo.axion.handler.flowcontrol.impl;

import com.google.common.util.concurrent.RateLimiter;
import com.mo.axion.common.domain.TaskInfo;
import com.mo.axion.handler.flowcontrol.FlowControlParam;
import com.mo.axion.handler.flowcontrol.FlowControlService;

/**
 * @author Mo
 * @createTime 2024/4/12 13:20
 * @description 发送用户数量流量控制服务实现类
 */
public class SendUserNumRateLimitServiceImpl implements FlowControlService {
    /**
     * 根据下发用户数量进行流量控制
     * @param taskInfo
     * @param flowControlParam
     * @return
     */
    @Override
    public Double flowControl(TaskInfo taskInfo, FlowControlParam flowControlParam) {
        RateLimiter rateLimiter = flowControlParam.getRateLimiter();
        return rateLimiter.acquire(taskInfo.getReceiver().size());
    }
}
